package com.netforce.util.convert;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.springframework.beans.factory.annotation.Autowired;

import com.netforce.util.io.IoManager;

public class InputStreamToStringConverter implements Converter<InputStream, String>
{
  @Override
  public String convert(InputStream aSource) throws ConverterException
  {
    try
    {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      IoManager.copy(aSource, outputStream);
      return new String(outputStream.toByteArray());
    }
    catch (IOException anException)
    {
      throw new ConverterException("Unable to convert inputstream to string", anException);
    }
  }

  @Autowired
  protected IoManager IoManager;
}
